//
//  main.m
//  03-NSStringAndNSValue
//
//  Created by dllo on 16/7/6.
//  Copyright © 2016年 dllo. All rights reserved.
//

#import <Foundation/Foundation.h>

int main(int argc, const char * argv[]) {
#if 0
    {
    // 1 查看头文件或者API, 他们的初始化/构造器, 基本上都放在一起
    // 2 当我们拿到一个新的类, 需要去查看这个类的初始化方法或者构造器
    /** 初始化(init) */
    NSString *string = [[NSString alloc] init];
    /** 便利构造器(string) */
    NSString *stri = @"hi";
    NSString *str = [NSString stringWithFormat:@"%@", stri];
    /** 获取字符串长度(length) */
    NSUInteger length = str.length;
    /** 获取字符串中字符(character) */
    [str characterAtIndex:0];
    /** 字符串是否相等(equal) */
    [str isEqualToString:@"hell"];
    /** 获取子串(sub) */
    [str substringFromIndex:0];
    /** 拼接字符串(append) */
#pragma mark - 如果字符串方法带有返回值, 操作的不是原字符串, 而是生成新的字符串
    [str stringByAppendingString:@"yo"];
    [str stringByAppendingFormat:@"i see%@", str];
    
    NSString *pathStr = @"/users/local/bin";
    pathStr = [pathStr stringByAppendingPathComponent:@"name.plist"];
    /** 替换字符串(replace) */
    [str stringByReplacingCharactersInRange:NSMakeRange(0, 1) withString:@"a"];
    /** 字符串对象转化为int类型(int) */
    [pathStr intValue];
    /** 字符串对象转化为其他数据类型, 例如double, float, BOOL等. */
    [pathStr doubleValue];
    [pathStr floatValue];
    [pathStr boolValue];
    /** 字符串全部大写(uppercase) */
    [pathStr uppercaseString];
    /** 字符串全部小写(lowercase) */
    [pathStr lowercaseString];
    /** 字符串首字母大写(capitalized) */
    [pathStr capitalizedString];
    /** 是否以指定字符串为前缀(prefix) */
    [pathStr hasPrefix:@"/"];
    /** 是否以指定字符串为后缀(suffix) */
    [pathStr hasSuffix:@"bin"];
    
#pragma mark - NSNumber
    int age = 10;
    NSNumber *ageNumber = [NSNumber numberWithInt:age];
    NSNumber *ageNumber1 = [[NSNumber alloc] initWithInt:age];
    NSNumber *ageNumber2 = @(age);
    }
#endif
    
#pragma mark - 练习
    NSString *str = @"330184198501184115";
    NSString *strYear = [str substringWithRange:NSMakeRange(6, 4)];
    NSString *strMonth = [str substringWithRange:NSMakeRange(10, 2)];
    NSString *strDay = [str substringWithRange:NSMakeRange(12, 2)];
    NSLog(@"%@年%@月%@日", strYear, strMonth, strDay);
    int year = strYear.intValue;
    NSLog(@"%d岁", 2016 - year);

    return 0;
}
